package com.paranoidvulture.javaEngine.MainPackage;
import java.awt.Color;
import java.awt.DisplayMode;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Window;
import java.awt.event.KeyListener;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelListener;

public abstract class Core implements KeyListener, MouseListener,
	MouseMotionListener, MouseWheelListener
{
	private static DisplayMode modes[] =
		{
			new DisplayMode(1280,1024,32,0),
			new DisplayMode(800,600,32,0),
			new DisplayMode(800,600,24,0),
			new DisplayMode(800,600,16,0),
			new DisplayMode(640,480,32,0),
			new DisplayMode(640,480,24,0),
			new DisplayMode(640,480,16,0),
		};
	private boolean running;
	protected ScreenManager s;
	
	//stop method
	public void stop()
	{
		running = false;		
	}
	
	//call init and gameloop
	public void run()
	{
		try
		{
			init();
			gameLoop();
		}finally{
			s.restoreScreen();
		}
	}
	
	//set to full screen
	public void init()
	{
		s = new ScreenManager();
		DisplayMode dm = s.findFirstCompatibleMode(modes);
		s.setFullScreen(dm);
		
		Window w = s.getFullScreenWindow();
		w.setFont(new Font("Arial",Font.PLAIN,20));
		w.setBackground(Color.green);
		w.setForeground(Color.white);
		w.setFocusTraversalKeysEnabled(false);
		w.addKeyListener(this);
		w.addMouseListener(this);
		w.addMouseMotionListener(this);
		w.addMouseWheelListener(this);
		running = true;
	}
	
	//main game loop
	public void gameLoop()
	{
		long startTime = System.currentTimeMillis();
		long cumTime = startTime;
		
		while(running)
		{
			long timePassed = System.currentTimeMillis() - cumTime;
			cumTime += timePassed;
			update(timePassed);
			
			Graphics2D g = s.getGraphics();
			draw(g);
			g.dispose();
			s.update();
			
			try
			{
				Thread.sleep(20);
			}catch(Exception ex){}
		}
		System.exit(0);
	}
	
	//update animation 
	public void update(long timePassed)
	{		
	}
	
	//draw stuff
	public abstract void draw(Graphics2D g);
	
	
}






































